﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.admin.product
{
    public partial class goods_batch_select_add : System.Web.UI.Page
    {


        // Methods
        private void Bind()
        {
            this.Labelcontent.Text = "<table width='98%' border='0' cellpadding='0' cellspacing='1'><tr bgcolor='#E2E7EB'><td align='left' class='title01' height='25'>商品名称</td><td align='left' class='title01'>进货价</td><td align='left' class='title01'>本店价格</td>";
            string sql = "Select * From tbMemberank";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.Labelcontent.Text = this.Labelcontent.Text + "<td align='left' class='title01'>" + row["rank"].ToString() + "</td>";
                }
            }
            this.Labelcontent.Text = this.Labelcontent.Text + "<td align='left' class='title01'>积分购买</td><td align='left' class='title01'>赠送积分</td><td align='left' class='title01'>库存</td><td align='left' class='title01'>品牌</td></tr>";
            if (base.Request.QueryString["pid"] != null)
            {
                string str2 = "Select * From DB_shoppro Where proid in (" + base.Request.QueryString["pid"] + ")";
                DataTable table2 = new DataTable();
                table2 = SQLAccess.GreatDs(str2).Tables[0];
                if (table2.Rows.Count > 0)
                {
                    this.Labelcontent.Text = this.Labelcontent.Text + "<tr>";
                    foreach (DataRow row2 in table2.Rows)
                    {
                        this.Labelcontent.Text = this.Labelcontent.Text + "<td>" + row2["proname"].ToString() + "</td>";
                        string text = this.Labelcontent.Text;
                        this.Labelcontent.Text = text + "<td><input id='proprice5_" + row2["proid"].ToString() + "' value='" + row2["proprice5"].ToString() + "' name='proprice5_" + row2["proid"].ToString() + "' runat='server' size='2' /></td>";
                        string str4 = this.Labelcontent.Text;
                        this.Labelcontent.Text = str4 + "<td><input id='proprice1_" + row2["proid"].ToString() + "' value='" + row2["proprice1"].ToString() + "' name='proprice1_" + row2["proid"].ToString() + "' runat='server' size='2' /></td>";
                        sql = "Select * From tbMemberprice where productid=" + row2["proid"].ToString() + "";
                        DataTable table3 = new DataTable();
                        table3 = SQLAccess.GreatDs(sql).Tables[0];
                        if (table3.Rows.Count > 0)
                        {
                            foreach (DataRow row3 in table3.Rows)
                            {
                                string str5 = this.Labelcontent.Text;
                                this.Labelcontent.Text = str5 + "<td><input id='proprice2_" + row2["proid"].ToString() + "_" + row3["rankid"].ToString() + "' value='" + row3["price"].ToString() + "' name='proprice2_" + row2["proid"].ToString() + "_" + row3["rankid"].ToString() + "' runat='server' size='2' /></td>";
                            }
                        }
                        string str6 = this.Labelcontent.Text;
                        this.Labelcontent.Text = str6 + "<td><input id='proscore2_" + row2["proid"].ToString() + "' value='" + row2["proscore2"].ToString() + "' name='proscore2_" + row2["proid"].ToString() + "' runat='server' size='2' /></td>";
                        string str7 = this.Labelcontent.Text;
                        this.Labelcontent.Text = str7 + "<td><input id='proscore1_" + row2["proid"].ToString() + "' value='" + row2["proscore1"].ToString() + "' name='proscore1_" + row2["proid"].ToString() + "' runat='server' size='2' /></td>";
                        string str8 = this.Labelcontent.Text;
                        this.Labelcontent.Text = str8 + "<td><input id='proku1_" + row2["proid"].ToString() + "' value='" + row2["proku1"].ToString() + "' name='proku1_" + row2["proid"].ToString() + "' runat='server' size='2' /></td>";
                        string str9 = this.Labelcontent.Text;
                        this.Labelcontent.Text = str9 + "<td><select name='propinpai_" + row2["proid"].ToString() + "' id='propinpai_" + row2["proid"].ToString() + "' runat='server'><option value='0'>请选择</option>";
                        sql = "Select * From DB_pinpai where visible=1";
                        DataTable table4 = new DataTable();
                        table4 = SQLAccess.GreatDs(sql).Tables[0];
                        if (table4.Rows.Count > 0)
                        {
                            foreach (DataRow row4 in table4.Rows)
                            {
                                if (row2["propinpai"].ToString() == row4["pinpaiid"].ToString())
                                {
                                    string str10 = this.Labelcontent.Text;
                                    this.Labelcontent.Text = str10 + "<option value='" + row4["pinpaiid"].ToString() + "' selected>" + row4["pinpainame"].ToString() + "</option>";
                                }
                                else
                                {
                                    string str11 = this.Labelcontent.Text;
                                    this.Labelcontent.Text = str11 + "<option value='" + row4["pinpaiid"].ToString() + "'>" + row4["pinpainame"].ToString() + "</option>";
                                }
                            }
                        }
                        this.Labelcontent.Text = this.Labelcontent.Text + "</select></td></tr>";
                    }
                }
            }
            this.Labelcontent.Text = this.Labelcontent.Text + "</table>";
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (base.Request.QueryString["pid"] != null)
            {
                string[] strArray = base.Request.QueryString["pid"].ToString().Split(new char[] { ',' });
                for (int i = 0; i < strArray.Length; i++)
                {
                    if ((strArray[i].ToString() != "0") && (strArray[i].ToString() != ""))
                    {
                        SQLAccess.DoSql("update DB_Shoppro set proprice5=" + base.Request.Form["proprice5_" + strArray[i]] + ",proprice1=" + base.Request.Form["proprice1_" + strArray[i]] + ",proscore1=" + base.Request.Form["proscore1_" + strArray[i]] + ",proscore2=" + base.Request.Form["proscore2_" + strArray[i]] + ",proku1=" + base.Request.Form["proku1_" + strArray[i]] + ",propinpai=" + base.Request.Form["propinpai_" + strArray[i]] + " where proid=" + strArray[i] + "");
                        string sql = "Select * From tbMemberprice where productid=" + strArray[i] + "";
                        DataTable table = new DataTable();
                        table = SQLAccess.GreatDs(sql).Tables[0];
                        if (table.Rows.Count > 0)
                        {
                            foreach (DataRow row in table.Rows)
                            {
                                SQLAccess.DoSql("update tbMemberprice set [price]=" + base.Request.Form["proprice2_" + strArray[i] + "_" + row["rankid"].ToString()] + " where rankid=" + row["rankid"].ToString() + " and productid=" + strArray[i] + "");
                            }
                        }
                    }
                }
                base.Response.Write("<script language='javascript'>alert('更新成功！');window.location.href='goods_batch_select.aspx';</script>");
                base.Response.End();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='../login.aspx';</script>");
                base.Response.End();
            }
            if (!base.IsPostBack)
            {
                this.Bind();
            }
        }


    }
}